import React, { Component } from 'react';
import { Link,withRouter } from 'react-router-dom';
import img1 from "../../style/images/photo-pic1.png"
import img2 from "../../style/images/jilu-pic1.jpg"
import * as tools from '../../config/tools'
import * as api from '../../config/api.js'
import './hospitallist.css'
const $ = window.$;
//医院列表
class Hospitallist extends Component {
    constructor(){
    super();
    this.state = {
        partyList:[],
        partyName:''
    }
  }
  componentDidMount() {
      this.show()
  }
  show(){
    let params={
        checkUpOrderId:this.props.match.params.checkUpOrderId,
        partyName:this.state.partyName
    }
    api.selectParty(params).then((data)=>{
      if(tools.checkResult(data)){
        this.setState({
            partyList:data.partyList,
            policyNo:data.policyNoAndPersonName.policyNo,
            personName:data.policyNoAndPersonName.personName
        })
      }else{
        tools.toast.error('网络错误');
      }
    })
  }
  query(e){
    this.setState({
        partyName:e.target.value
    })
  }
  hospitalinfo(partyId){
    localStorage.setItem('personName', this.state.personName);
    localStorage.setItem('checkUpOrderId', this.props.match.params.checkUpOrderId);
    localStorage.setItem('partyId', partyId);
    this.props.history.push(`/hospitalinfo/${partyId}`)
  }
  render() {
    return (
      <div className='hospitallist' >
      <header>
      <div className="yiyuan-list">
      <dl>
      <dt><img src={img1} className="width100" /></dt>
      <dd>
      <p>{this.state.personName}</p>
      <p>保单号:{this.state.policyNo}</p>
      </dd>
      </dl>
      </div>
      </header>
      <div className="mui-content">
      <div className="jilu-search">
      <div className="mui-search mui-active">
      <input type="search" 
      className="search_input mui-input-clear mui-indexed-list-search-input" 
      placeholder=""
      value={this.state.partyName} onChange={(e)=>{this.query(e)}} />
      <button className='search_btn' onClick={()=>this.show()} >搜索</button>
      </div>
      </div>            
      </div>
      {this.state.partyList.map((item,index)=>{
        return(
          <div className="mui-content" key={index} onClick={()=>{this.hospitalinfo(item.partyId)}}> 
          <div className="yiyuan-content">                
          <dl>
          <dt><img src={img2} className="width100" /></dt>
          <dd>
          <p className="title">{item.partyName}</p>
          <p className="dizi">{item.partyAddress}</p>
          </dd>
          </dl>                
          </div>   
          </div>
          )
      })} 
      </div>
    );
  }
}

export default withRouter(Hospitallist);